package edu.zzuli.util;

/**
 * @author tianshaojie
 * @date 2011-7-16
 * @discription : 分页工具类，组织分页查询SQL
 */
public class PaginationUtil {
	
	/**
	 * @author tianshaojie
	 * @date 2011-7-16
	 * @discription : 组织分页查询SQL
	 * @param sql
	 * @param currentPage
	 * @param pageRowBegin
	 * @param pageRowEnd
	 * @return String
	 */
	public static String getLimitString(String sql, int currentPage, int pageRowBegin, int pageRowEnd) {
		StringBuffer pagingSelect = new StringBuffer();
		pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
		pagingSelect.append(sql);
		if (currentPage != 1)
			pagingSelect.append(" ) row_ ) where rownum_ <= " + pageRowEnd + " and rownum_ >= " + pageRowBegin);
		else {
			pagingSelect.append(" ) row_ ) where rownum_ <= " + pageRowEnd);
		}
		return pagingSelect.toString();
	}

}
